package com.zeei.ems.meet.controller;

import com.github.pagehelper.PageInfo;
import com.zeei.ems.base.constant.GlobalConstant;
import com.zeei.ems.base.controller.BasicController;
import com.zeei.ems.base.page.PageParamVO;
import com.zeei.ems.base.result.ResultBasicVO;
import com.zeei.ems.base.result.ResultRowsVO;
import com.zeei.ems.base.util.StringUtil;
import com.zeei.ems.meet.model.TaskDetailVO;
import com.zeei.ems.meet.model.TaskNewVO;
import com.zeei.ems.meet.model.vo.TaskNewParam;
import com.zeei.ems.meet.service.DataRtService;
import com.zeei.ems.meet.service.TaskNewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "任务管理接口")
@RestController
@RequestMapping("/ems/task")
public class TaskNewController extends BasicController {
    @Autowired
    TaskNewService taskNewService;
    @Autowired
    DataRtService dataRtService;

    /**
     * 查询任务信息列表
     * @param taskCode 任务编码
     * @return 返回任务信息列表
     */
    @ApiOperation(value = "查询任务信息列表")
    @PostMapping("/detail")
    public ResultRowsVO<TaskDetailVO> listTaskNewDetail(String taskCode){
        List<TaskDetailVO> taskDetailList = dataRtService.listDataRtTaskDetail(taskCode);
        return this.createResultRowsVO(taskDetailList, GlobalConstant.SUCCEED, taskDetailList.size());
    }

    /**
     * 分页查询任务信息列表
     * @param taskNewParam 任务信息
     * @return 返回任务信息列表
     */
    @ApiOperation(value = "分页查询任务信息列表")
    @PostMapping("/page/list")
    public ResultRowsVO<TaskNewVO> listTaskNew(PageParamVO page,
                                               @RequestBody TaskNewParam taskNewParam){
        PageInfo<TaskNewVO> taskNewVOPageInfo = taskNewService.listTaskNew(page, taskNewParam);
        return this.createResultRowsVO(taskNewVOPageInfo, GlobalConstant.SUCCEED, "");
    }

    /**
     * 查询任务信息列表
     * @param taskNewParam 任务信息
     * @return 返回任务信息列表
     */
    @ApiOperation(value = "查询任务信息列表")
    @PostMapping("/list")
    public ResultRowsVO<TaskNewVO> listTaskNew(@RequestBody TaskNewParam taskNewParam){
        List<TaskNewVO> taskNewList = taskNewService.listTaskNew(taskNewParam);
        return this.createResultRowsVO(taskNewList, GlobalConstant.SUCCEED, taskNewList.size());
    }

    /**
     * 查询当前未完成任务信息列表
     * @return 返回当前未完成任务信息列表
     */
    @ApiOperation(value = "查询当前未完成任务信息列表")
    @PostMapping("/list/current")
    public ResultRowsVO<TaskNewVO> listTaskNewCurrent(){
        List<TaskNewVO> taskNewList = taskNewService.listTaskNewCurrent();
        return this.createResultRowsVO(taskNewList, GlobalConstant.SUCCEED, taskNewList.size());
    }

    /**
     * 下发任务
     * @param taskId 任务ID
     * @return 返回下发是否成功
     */
    @ApiOperation(value = "下发任务信息")
    @PostMapping("/down")
    public ResultBasicVO downTaskNew(Integer taskId){
        Boolean result = taskNewService.downTaskNew(taskId);
        return this.createResultBasicVO(result, StringUtil.empty());
    }

    /**
     * 新增任务信息
     * @param taskNew 任务信息
     * @return 返回是否新增成功
     */
    @ApiOperation(value = "新增任务信息")
    @PostMapping("/add")
    public ResultBasicVO addTaskNew(@RequestBody TaskNewVO taskNew){
        Boolean result = taskNewService.addTaskNew(taskNew);
        return this.createResultBasicVO(result, StringUtil.empty());
    }

    /**
     * 更新任务信息
     * @param taskNew 任务信息
     * @return 返回是否新增成功
     */
    @ApiOperation(value = "更新任务信息")
    @PostMapping("/update")
    public ResultBasicVO  updateTaskNew(@RequestBody TaskNewVO taskNew){
        Boolean result = taskNewService.updateTaskNew(taskNew);
        return this.createResultBasicVO(result, StringUtil.empty());
    }

    /**
     * 删除任务信息
     * @param taskIdList 任务ID集合
     * @return 返回是否新增成功
     */
    @ApiOperation(value = "删除任务信息")
    @PostMapping("/delete")
    public ResultBasicVO  deleteTaskNew(@RequestBody List<Integer> taskIdList){
        Boolean result = taskNewService.deleteTaskNew(taskIdList);
        return this.createResultBasicVO(result, StringUtil.empty());
    }
}
